<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="isAlls">
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      @keydown.enter="add"
      v-model.trim="task"
    />
  </header>
</template>

<script>
export default {
  data() {
    return {
      isAll:false,
      task:''
    }
  },
  props: ['list'],
  computed:{
    isAlls:{
      set(val) {
        // this.$emit('isAll',val)
        this.list.forEach(item => item.isDone = val)
        // console.log(val);
      },
      get() {
        return this.list.every(item=>item.isDone)
      }
    }
  },
 methods:{
   add() {
    if( this.task.trim().length > 0) {
      this.$emit('addBtn',this.task)
    this.task = ''
    } else {
      alert('不能输入内容为空')
    }
  },
 }
}
</script>
